home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / MetaSchemaFlavor.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  7.4 KB  |  213 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.xml.dt.DataType;
  4. import com.extensibility.xml.dt.DataTypeIntf;
  5. import java.io.IOException;
  6. import java.util.Enumeration;
  7. import java.util.Vector;
  8.  
  9. public class MetaSchemaFlavor extends XDRFlavor implements ExtraMetaDataUIIntf {
  10.    String name;
  11.    SchemaIntf metaschema;
  12.    Vector elemDefs = new Vector();
  13.    Vector elemRefs = new Vector();
  14.    Vector attrDefs = new Vector();
  15.    Vector schemaProps = new Vector();
  16.  
  17.    public MetaSchemaFlavor(SchemaIntf var1, String var2) {
  18.       super(var1);
  19.       this.name = var2;
  20.    }
  21.  
  22.    public void setMetaschema(URI var1) throws Exception {
  23.       String var2 = SchemaUtilities.getFlavor(var1, false);
  24.       this.metaschema = new Schema(var1, var2);
  25.       this.metaschema.parse(var1, 0, (Object)null);
  26.       this.createMetaInfo();
  27.    }
  28.  
  29.    public String getFlavorName() {
  30.       return this.name;
  31.    }
  32.  
  33.    public String getExtensionsName() {
  34.       String var1 = (String)this.metaschema.getMetaPropHash().getMetaProp("xams:name");
  35.       return var1 != null ? var1 : this.name;
  36.    }
  37.  
  38.    public static boolean isValid(String var0, URI var1) {
  39.       String var2 = var1.getFullName();
  40.       if (var2.indexOf(String.valueOf(".").concat(String.valueOf(var0))) == var2.length() - var0.length() - 1) {
  41.          return true;
  42.       } else {
  43.          return SchemaUtilities.getFlavor(var1, false) != null;
  44.       }
  45.    }
  46.  
  47.    public void parse(URI var1, URI var2, int var3, Object var4) throws IOException {
  48.       super.parse(var1, var2, var3, var4);
  49.       String[] var5 = this.getNamespaces();
  50.       if (var5 != null) {
  51.          for(int var6 = 0; var6 < var5.length - 1; var6 += 2) {
  52.             NamespaceDeclaration var7 = super.schema.getNamedNamespace(var5[var6]);
  53.             if (var7 != null) {
  54.                super.schema.removeDeclaration(var7);
  55.             }
  56.          }
  57.       }
  58.  
  59.    }
  60.  
  61.    protected void buildInfos(String var1, Vector var2) {
  62.       ElementDeclaration var3 = this.metaschema.getNamedElement(var1);
  63.       if (var3 != null) {
  64.          ContentModelTermEnum var4 = var3.getContentModel().getLeafTerms();
  65.  
  66.          while(var4.hasMoreElements()) {
  67.             ContentModelTerm var5 = var4.nextContentModelTerm();
  68.             CMTReferent var6 = var5.getReferent();
  69.             if (var6 instanceof ElementDeclaration) {
  70.                ElementDeclaration var7 = (ElementDeclaration)var6;
  71.                Class var8 = this.getClass(var7);
  72.                double var9 = this.getWeight(var7);
  73.                int var11 = this.getWidth(var7);
  74.                String var12 = this.getColName(var7);
  75.                String var13 = this.getIdFrom(var7);
  76.                var2.addElement(new MetaPropUIInfo(var12, String.valueOf(String.valueOf(this.name).concat(String.valueOf(":"))).concat(String.valueOf(var5.getTerm())), var8, var9, var11, var13, var7.getDataType(), (String)null));
  77.             }
  78.          }
  79.  
  80.          Enumeration var16 = var3.getOwnedAttributes();
  81.  
  82.          while(var16.hasMoreElements()) {
  83.             AttributeDeclaration var17 = (AttributeDeclaration)var16.nextElement();
  84.             String var18 = ((BaseDeclaration)var17).getName();
  85.             if (!var18.equals("which")) {
  86.                Class var19 = this.getClass(var17);
  87.                double var20 = this.getWeight(var17);
  88.                int var21 = this.getWidth(var17);
  89.                String var22 = this.getColName(var17);
  90.                String var23 = this.getIdFrom(var17);
  91.                DataType var14 = var17.getDataType();
  92.                String var15 = var17.getDefault();
  93.                var2.addElement(new MetaPropUIInfo(var22, String.valueOf(String.valueOf(this.name).concat(String.valueOf(":"))).concat(String.valueOf(var18)), var19, var20, var21, var23, var14, var15));
  94.             }
  95.          }
  96.       }
  97.  
  98.    }
  99.  
  100.    protected Class getClass(BaseDeclaration var1) {
  101.       return Class.forName("java.lang.String");
  102.    }
  103.  
  104.    protected double getWeight(BaseDeclaration var1) {
  105.       Object var2 = var1.getMetaProp("xams:colWeight");
  106.       return var2 == null ? 0.1 : Double.valueOf(var2.toString());
  107.    }
  108.  
  109.    protected int getWidth(BaseDeclaration var1) {
  110.       Object var2 = var1.getMetaProp("xams:colWidth");
  111.       return var2 == null ? 80 : Integer.valueOf(var2.toString());
  112.    }
  113.  
  114.    protected String getColName(BaseDeclaration var1) {
  115.       Object var2 = var1.getMetaProp("xams:colName");
  116.       return var2 == null ? var1.getName() : var2.toString();
  117.    }
  118.  
  119.    protected String getIdFrom(BaseDeclaration var1) {
  120.       Object var2 = var1.getMetaProp("xams:idFrom");
  121.       return var2 == null ? "" : var2.toString();
  122.    }
  123.  
  124.    protected void createMetaInfo() {
  125.       this.buildInfos("element", this.elemDefs);
  126.       this.buildInfos("subelement", this.elemRefs);
  127.       this.buildInfos("attribute", this.attrDefs);
  128.       this.buildInfos("schema", this.schemaProps);
  129.    }
  130.  
  131.    public int getExtraColumnCount(int var1) {
  132.       return this.getCount(var1);
  133.    }
  134.  
  135.    public String getColumnName(int var1, int var2) {
  136.       return this.getInfo(var1, var2).colName;
  137.    }
  138.  
  139.    public Class getColumnClass(int var1, int var2) {
  140.       return this.getInfo(var1, var2).colClass;
  141.    }
  142.  
  143.    public int getInitialColumnWidth(int var1, int var2) {
  144.       return this.getInfo(var1, var2).colInitialWidth;
  145.    }
  146.  
  147.    public double getColumnWeight(int var1, int var2) {
  148.       return this.getInfo(var1, var2).colWeight;
  149.    }
  150.  
  151.    public String getColumnIdFrom(int var1, int var2) {
  152.       return this.getInfo(var1, var2).idFrom;
  153.    }
  154.  
  155.    public String getColumnMetaProp(int var1, int var2) {
  156.       return this.getInfo(var1, var2).metaprop;
  157.    }
  158.  
  159.    public boolean isColumnMetaPropList(int var1, int var2) {
  160.       return this.getInfo(var1, var2).isListOfSubElements;
  161.    }
  162.  
  163.    public boolean isColumnMetaPropAttrs(int var1, int var2) {
  164.       return this.getInfo(var1, var2).isSubElementWithAttrs;
  165.    }
  166.  
  167.    public DataTypeIntf getDataType(int var1, int var2) {
  168.       return this.getInfo(var1, var2).dataType;
  169.    }
  170.  
  171.    public String getDefaultValue(int var1, int var2) {
  172.       return this.getInfo(var1, var2).defaultValue;
  173.    }
  174.  
  175.    public String[] getNamespaces() {
  176.       String var1 = (String)this.metaschema.getMetaPropHash().getMetaProp("xams:namespace");
  177.       if (var1 == null && this.metaschema.getNamespace() != null) {
  178.          var1 = this.metaschema.getNamespace().toSource();
  179.       }
  180.  
  181.       if (var1 == null) {
  182.          var1 = "";
  183.       }
  184.  
  185.       return new String[]{this.name, var1};
  186.    }
  187.  
  188.    protected int getCount(int var1) {
  189.       Vector var2 = this.getInfo(var1);
  190.       return var2 == null ? 0 : var2.size();
  191.    }
  192.  
  193.    protected Vector getInfo(int var1) {
  194.       switch (var1) {
  195.          case 1:
  196.             return this.elemDefs;
  197.          case 2:
  198.             return this.elemRefs;
  199.          case 3:
  200.          case 4:
  201.             return this.attrDefs;
  202.          case 5:
  203.             return this.schemaProps;
  204.          default:
  205.             return null;
  206.       }
  207.    }
  208.  
  209.    protected MetaPropUIInfo getInfo(int var1, int var2) {
  210.       return (MetaPropUIInfo)this.getInfo(var1).elementAt(var2);
  211.    }
  212. }
  213.